#/bin/bash

if [[ -z $@ ]]
then
	echo 'Usage: bash complie.bash tex_filename_without_extension'
	exit
fi
cp ~/texmf/tex/latex/math/*.sty -v ./
#echo "Not copying packages!!!"
pdflatex -no-shell-escape $@.tex
bibtex $@.aux
if which texindy &> /dev/null
then
	rm $@.indo $@.ind
	texindy -M texindy -M tex/inputenc/iso88595 -L russian -C iso88595 -o $@.indo $@.idx
	iconv -f iso88595 -t utf8 $@.indo > $@.ind
else
	echo "No TeXindy detected on this machine. Index won\'t be regenerated." 2>&1
fi
pdflatex -no-shell-escape $@.tex
pdflatex -no-shell-escape $@.tex
